import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/7 15:15
 * @description Map
 */
public class Solution {
    public static void main(String[] args) {

    }
    public List<String> alertNames(String[] keyName, String[] keyTime) {
        Map<String, List<Integer>> map = new HashMap<>();
        int n = keyName.length;
        for (int i = 0; i < n; i++) {
            String time = keyTime[i];
            // 将字符串时间转换为整数，方便比较
            int hour = Integer.parseInt(time.substring(0, 2));
            int min = Integer.parseInt(time.substring(3));
            map.putIfAbsent(keyName[i], new ArrayList<>());
            map.get(keyName[i]).add(hour * 60 + min);
        }
        List<String> ans = new ArrayList<>();
        for (Map.Entry<String, List<Integer>> entry: map.entrySet()) {
            List<Integer> list = entry.getValue();
            Collections.sort(list);
            for (int i = 2; i < list.size(); i++) {
                int first = list.get(i-2), third = list.get(i);
                if (third - first <= 60) {
                    ans.add(entry.getKey());
                    break;
                }
            }
        }
        Collections.sort(ans);
        return ans;
    }
}
